var layer;
var $;
var element;
var form;
var laydate;
var table;
layui.use(['element','layer','laydate','form','table'], function(){
    layer = layui.layer;
    $ = layui.jquery;
    element = layui.element;
    form = layui.form;
    laydate = layui.laydate;
    table = layui.table;
    //执行一个laydate实例
    laydate.render({
        elem: '#createDate', //指定元素
        type: 'date',
        trigger: 'click' //时间时间为点击事件
    });
    load();
    selIndexUserTab(3,'');
    selAduFeedNum();
    $("input[name=status]").val(3);
})
/**
 *  展示待审核   以及已审核的数量
 * */
function selAduFeedNum(){
    $.get("/personnel/selAduFeedNum", function (res) {
        $("#waitNum").html(res.data.waitNum);
        $("#acceptedNum").html(res.data.acceptedNum);
    });
}
/**
 *  点击事件  刷新  返回
 * */
function load(){
    $(".tit_btn").bind('click',function(){
        location.reload();
    });
    $("#Adu_btn1").bind('click',function(){
        $("#Adu_btn1").removeClass("layui-btn-primary");
        $("#Adu_btn2").addClass("layui-btn-primary");
        $("input[name=status]").val(3);
        selIndexUserTab(3);
    })
    $("#Adu_btn2").bind('click',function(){
        $("#Adu_btn1").addClass("layui-btn-primary");
        $("#Adu_btn2").removeClass("layui-btn-primary");
        $("input[name=status]").val(4);
        selIndexUserTab(4);
    })
    $("#indexBtn").bind('click',function(){
        var obj = '';
        var account = $("input[name=account]").val();
        var feedbackType = $("select[name=feedbackType]").val();
        var feedbackClassification = $("select[name=feedbackClassification]").val();
        var createDate = $("input[name=createDate]").val();
        if(!account){
            obj+="&account="+'';
        }else{
            obj+="&account="+account;
        }
        if(!feedbackType){
            obj+="&feedbackType="+0;
        }else{
            obj+="&feedbackType="+feedbackType;
        }
        if(!feedbackClassification){
            obj+="&feedbackClassification="+0;
        }else{
            obj+="&feedbackClassification="+feedbackClassification;
        }
        if(!createDate){
            obj+="&createDate="+'';
        }else{
            obj+="&createDate="+createDate;
        }
        var status = $("input[name=status]").val();
        if(status==3){
            if(!status){
                obj+="&feedbackStatus="+0;
            }else{
                obj+="&feedbackStatus="+status;
            }
            selIndexUserTab(3,obj);
        }else if(status==4){
            if(!status){
                obj+="&feedbackStatus="+0;
            }else{
                obj+="&feedbackStatus="+status;
            }
            selIndexUserTab(4,obj);
        }
    });
}
/**
 *  封号用户列表
 */
function selIndexUserTab(status,vals){
    if(status==3){
        if(!status){
            vals+="&feedbackStatus="+0;
        }else{
            vals+="&feedbackStatus="+status;
        }
        $.ajax({
            url:"/personnel/selFeedbackList",
            type:"post",
            dataType:"json",
            data:vals,
            success:function(item) {
                userTab(item.data);
            }
        })
    }else if(status==4){
        if(!status){
            vals+="&feedbackStatus="+0;
        }else{
            vals+="&feedbackStatus="+status;
        }
        $.ajax({
            url:"/personnel/selFeedbackList",
            type:"post",
            dataType:"json",
            data:vals,
            success:function(item) {
                userAcctepTab(item.data);
            }
        })
    }
}
function userTab(item){
    table.render({
        elem:"#userListTab",//容器
        title:"用户反馈数据列表",
        data:item,
        toolbar:true,
        page:true,
        cols:[[//定义列
            {type:'checkbox',align:'center',width:60},//复选框靠左
            {title:'序号',align:'center',width:120,templet:function(data){
                    return data.LAY_INDEX;
                }},
            {field:"account",title:"用户账号",align:'center',width:120},
            {field:"feedbackType",title:"意见反馈类型",align:'center',width:140,templet:function(data){
                    if(data.feedbackType==2){
                        return "视频反馈";
                    }else if(data.feedbackType==3){
                        return "商品反馈";
                    }else if(data.feedbackType==4){
                        return "其他反馈";
                    }
                }},
            {field:"feedbackClassification",title:"意见分类",align:'center',width:120,templet:function(data){
                    if(data.feedbackClassification==2){
                        return "很好";
                    }else if(data.feedbackClassification==3){
                        return "好";
                    }else if(data.feedbackClassification==4){
                        return "一般";
                    }else if(data.feedbackClassification==5){
                        return "差";
                    }
                }},
            {field:"createDate",title:"反馈时间",align:'center',width:180,templet:function(data){
                    return renderTime(data.createDate) ;
                }},
            {field:"feedbackContent",title:"反馈内容",align:'center',width:220},
            {field:"",title:"操作",align:'center',templet:function(data){
                    return "<a style='color:#009688;cursor:pointer;' onclick='auditFeedback(\""+data.feedbackId+"\")'>受理</a> ";
                }}
        ]]
    });
}
function userAcctepTab(item){
    table.render({
        elem:"#userListTab",//容器
        title:"用户反馈数据列表",
        data:item,
        toolbar:true,
        page:true,
        cols:[[//定义列
            {type:'checkbox',align:'center',width:60},//复选框靠左
            {title:'序号',align:'center',width:120,templet:function(data){
                    return data.LAY_INDEX;
                }},
            {field:"account",title:"用户账号",align:'center',width:120},
            {field:"feedbackType",title:"意见反馈类型",align:'center',width:140,templet:function(data){
                    if(data.feedbackType==2){
                        return "视频反馈";
                    }else if(data.feedbackType==3){
                        return "商品反馈";
                    }else if(data.feedbackType==4){
                        return "其他反馈";
                    }
                }},
            {field:"feedbackClassification",title:"意见分类",align:'center',width:120,templet:function(data){
                    if(data.feedbackClassification==2){
                        return "很好";
                    }else if(data.feedbackClassification==3){
                        return "好";
                    }else if(data.feedbackClassification==4){
                        return "一般";
                    }else if(data.feedbackClassification==5){
                        return "差";
                    }
                }},
            {field:"createDate",title:"反馈时间",align:'center',width:180,templet:function(data){
                        return renderTime(data.createDate) ;
                }},
            {field:"feedbackContent",title:"反馈内容",align:'center',width:220},
            {field:"",title:"操作",align:'center',templet:function(data){
                    return "<a style='color:#009688;cursor:pointer;' onclick='auditFeedbackInfo(\""+data.feedbackId+"\")'>受理详情</a> " +
                        "<a style='color:#009688;cursor:pointer;' onclick='selAduitInfo(\""+data.feedbackId+"\")'>查看</a> " +
                        "<a style='color:#009688;cursor:pointer;' onclick='delFeedback(\""+data.feedbackId+"\")'>删除</a>" ;
                }}
        ]]
    });
}
/**
 *  受理反馈信息
 */
function auditFeedback(id){
    layer.open({
        type:2,//弹出层的类型
        title:"受理用户反馈信息",
        area:['1100px','650px'],//弹出层大小
        shade:0,//设置遮罩
        offset:'auto',//设置遮罩的位置
        maxmin:true,
        //弹出层内容
        content :"/personnel/layer/PerFeedback_layer_auditFeedback.html",
        btn:['受理','取消'],
        yes:function(index,layero){
            layer.confirm('您确定要受理此意见吗?', function (rel) {
                var feedbackStatus = 4;
                $.post("/personnel/updFeedback", {feedbackStatus:feedbackStatus,feedbackId:id}, function (res) {
                    if(res.data){
                        selIndexUserTab(3);
                        var tablename = "用户反馈数据列表";
                        var remark = id+"";
                        var type = 4;
                        addOperLogin(tablename,type,remark);
                        layer.msg("受理成功", {icon: 1});
                        layer.closeAll('iframe');
                    }else{
                        selIndexUserTab(3);
                        layer.msg("受理失败", {icon: 2});
                        layer.closeAll('iframe');
                    }
                });
            });
        },btn2:function(){

        },success:function(layero,index){
            var obj = layero.find('iframe').contents();
            var vals='';
            vals+="&feedbackId="+id;
            $.post("/personnel/selFeedbackList", vals, function (res) {
                var item = res.data;
                obj.find("input[name=account]").val(item[0].account);
                if(item[0].feedbackType==2){
                    obj.find("input[name=feedbackStatus]").val("视频反馈");
                }else if(item[0].feedbackType==3){
                    obj.find("input[name=feedbackStatus]").val("商品反馈");
                }else if(item[0].feedbackType==4){
                    obj.find("input[name=feedbackStatus]").val("其他反馈");
                }
                if(item[0].feedbackClassification==2){
                    obj.find("input[name=feedbackClassification]").val("很好");
                }else if(item[0].feedbackClassification==3){
                    obj.find("input[name=feedbackClassification]").val("好");
                }else if(item[0].feedbackClassification==4){
                    obj.find("input[name=feedbackClassification]").val("一般");
                }else if(item[0].feedbackClassification==5){
                    obj.find("input[name=feedbackClassification]").val("差");
                }
                obj.find("input[name=createDate]").val(item[0].createDate);
                obj.find("textarea[name=feedbackContent]").val(item[0].feedbackContent);
                obj.find("input[name=pictureUrl]").val(item[0].pictureUrl);
            });
        }
    })
}
/**
 *  查看受理详情
 */
function auditFeedbackInfo(id){
    layer.open({
        type:2,//弹出层的类型
        title:"受理详情",
        area:['600px','300px'],//弹出层大小
        shade:0,//设置遮罩
        offset:'auto',//设置遮罩的位置
        maxmin:true,
        //弹出层内容
        content :"/personnel/layer/PerFeedback_layer_receiveInfo.html",
        btn:['关闭','取消'],
        yes:function(index,layero){
            layer.closeAll('iframe');
        },btn2:function(){

        },success:function(layero,index){
            var obj = layero.find('iframe').contents();
            var vals = '';
            var tablename = "用户反馈数据列表";
            var remark = id+"";
            vals+="&tablename="+tablename;
            vals+="&remark="+remark;
            $.post("/personnel/selReceiveInfo", vals, function (res) {
                obj.find(".trueName").html(res.data.trueName);
                obj.find(".createDate").html(res.data.createDate);
            })
        }
    })
}
/**
 *  查看反馈信息
 */
function selAduitInfo(id){
    var tablename = "用户反馈数据列表";
    var type = 5;
    var remark = id+"";
    addOperLogin(tablename,type,remark);
    layer.open({
        type:2,//弹出层的类型
        title:"用户反馈信息",
        area:['1100px','650px'],//弹出层大小
        shade:0,//设置遮罩
        offset:'auto',//设置遮罩的位置
        maxmin:true,
        //弹出层内容
        content :"/personnel/layer/PerFeedback_layer_auditFeedback.html",
        btn:['关闭','取消'],
        yes:function(index,layero){
            layer.closeAll('iframe');
        },btn2:function(){

        },success:function(layero,index){
            var obj = layero.find('iframe').contents();
            var vals='';
            vals+="&feedbackId="+id;
            $.post("/personnel/selFeedbackList", vals, function (res) {
                var item = res.data;
                obj.find("input[name=account]").val(item[0].account);
                if(item[0].feedbackType==2){
                    obj.find("input[name=feedbackStatus]").val("视频反馈");
                }else if(item[0].feedbackType==3){
                    obj.find("input[name=feedbackStatus]").val("商品反馈");
                }else if(item[0].feedbackType==4){
                    obj.find("input[name=feedbackStatus]").val("其他反馈");
                }
                if(item[0].feedbackClassification==2){
                    obj.find("input[name=feedbackClassification]").val("很好");
                }else if(item[0].feedbackClassification==3){
                    obj.find("input[name=feedbackClassification]").val("好");
                }else if(item[0].feedbackClassification==4){
                    obj.find("input[name=feedbackClassification]").val("一般");
                }else if(item[0].feedbackClassification==5){
                    obj.find("input[name=feedbackClassification]").val("差");
                }
                obj.find("input[name=createDate]").val(item[0].createDate);
                obj.find("textarea[name=feedbackContent]").val(item[0].feedbackContent);
                obj.find("input[name=pictureUrl]").val(item[0].pictureUrl);
            });
        }
    })
}
/**
 *  删除反馈信息
 */
function delFeedback(id){
    layer.confirm('您确定要删除此反馈吗?', function (rel) {
        $.post("/personnel/delFeedback", {feedbackId:id}, function (res) {
            if(res.data){
                var tablename = "用户反馈数据列表";
                var type = 3;
                var remark = id+"";
                addOperLogin(tablename,type,remark);
                layer.msg("删除成功", {icon: 1});
                selIndexUserTab(4);
            }
        });
    });
}
/**
 *  添加后台操作日志
 * */
function addOperLogin(tablename,type,remark){
    var create=localStorage.getItem("user");
    create=JSON.parse(create);//将获取json字符串转json对象
    var mid = create.user_id;
    form+="&mid="+mid;
    form+="&tablename="+tablename;
    form+="&type="+type;
    form+="&remark="+remark;
    $.post("/personnel/addOperationLog", form, function (res) {
        form="";
    });
}